package com.gongzhiyun.springboot3test.controller;

import com.gongzhiyun.springboot3test.base.PageBean;
import com.gongzhiyun.springboot3test.base.R;
import com.gongzhiyun.springboot3test.entity.user.TbUserExinfo;
import com.gongzhiyun.springboot3test.entity.user.TbUserPrivate;
import com.gongzhiyun.springboot3test.service.UserService;
import com.gongzhiyun.springboot3test.validate.CommonValidate;
import com.gongzhiyun.springboot3test.vo.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/user")
@Tag(name = "用户相关功能")
public class UserController {
    private final UserService userService;

    @Operation(summary = "更新用户头像",description = "更新用户头像")
    @PostMapping("/updatelogo")
    public R<String> updatelogo(@RequestBody TbUserExinfo logo){
        return userService.updateLogo(logo.getLogo());
    }


    @Operation(summary = "查询用户头像url",description = "查询用户头像")
    @GetMapping("/logo/{uid}")
    public String logo(@PathVariable("uid") Integer uid){
        return userService.logoByUid(uid);
    }

    @Operation(summary = "查询用户信息",description = "查询用户信息")
    @GetMapping("/queryById/{uid}")
    public R<UserInfo> queryById(@PathVariable("uid") Integer uid){
        return userService.queryById(uid);
    }


//    @PostMapping("/privates")
//    public R<String> privates(@RequestBody TbUserPrivate tbUserPrivate){
//        return userService.privates(tbUserPrivate);
//    }
//
//    @GetMapping("/queryPrivates/{pn}/{ps}/{order}")
//    public R<List<TbUserPrivate>> queryPrivates(@RequestBody TbUserPrivate userPrivate,@PathVariable("pn") Integer pn,@PathVariable("ps") Integer ps,@PathVariable("order") Integer order){
//        PageBean pageBean=new PageBean();
//        pageBean.setPageNum(pn);
//        pageBean.setPageSize(ps);
//        pageBean.setOrder(order);
//        return userService.queryPrivates(userPrivate,pageBean);
//    }
//
//    @GetMapping("/delPrivates/{id}")
//    public R<String> delPrivates(@PathVariable("id") Integer id){
//        return userService.delPrivates(id);
//    }



    @Operation(summary = "用户注册",description = "用户注册")
    @PostMapping("/reg")
    public R<String> reg(@RequestBody @Validated(CommonValidate.reg.class) UserParams userParams) {
        return userService.reg(userParams);
    }

    @Operation(summary = "用户登录",description = "用户登录")
    @PostMapping("/login")
    public R<UserInfo> login(@RequestBody UserParams userParams) {
        return userService.login(userParams);
    }

    @Operation(summary = "用户安全退出",description = "用户安全退出")
    @PostMapping("/logout")
    public R<String> logout() {
        return userService.logout();
    }

    @Operation(summary = "修改密码",description = "修改密码,需要登录")
    @PostMapping("/updatePwd")
    public R<String> updatePwd(@RequestBody @Validated(CommonValidate.update.class) ParamsPwd pwd) {
        return userService.updatePwd(pwd);
    }

    @Operation(summary = "修改用户信息",description = "修改用户信息,需要登录")
    @PostMapping("/updateInfo")
    public R<String> updateInfo(@RequestBody ParamsInfo info) {
        return userService.updateInfo(info);
    }

    @Operation(summary = "获取登录用户信息",description = "获取登录用户信息")
    @PostMapping("/getLoginInfo")
    public R<UserInfo> getLoginInfo() {
        return userService.getLoginInfo();
    }


    @Operation(summary = "管理员删除用户",description = "删除用户，需要管理员登录")
    @PostMapping("/isDelUser")
    public R<String> isDelUser(@RequestBody ParamsDel paramsDel) {
        return userService.isDelUser(paramsDel);
    }

    @Operation(summary = "关注用户",description = "关注用户,需要登录")
    @GetMapping("/follow/{uid}")
    public R<String> follow(@PathVariable("uid") Integer uid) {
        return userService.concern(uid);
    }

    @Operation(summary = "查询用户的关注",description = "查询关注用户")
    @GetMapping("/queryfollow/{uid}/{pn}/{ps}")
    public R<List<UserInfo>> queryFollow(@PathVariable("uid") Integer uid, @PathVariable("pn") Integer pn, @PathVariable("ps") Integer ps) {
        PageBean pageBean = new PageBean();
        pageBean.setPageNum(pn);
        pageBean.setPageSize(ps);
        return userService.queryFollow(uid, pageBean);
    }

    @Operation(summary = "查询用户的粉丝",description = "查询被关注用户")
    @GetMapping("/queryfollowed/{uid}/{pn}/{ps}")
    public R<List<UserInfo>> queryFollowed(@PathVariable("uid") Integer uid, @PathVariable("pn") Integer pn, @PathVariable("ps") Integer ps) {
        PageBean pageBean = new PageBean();
        pageBean.setPageNum(pn);
        pageBean.setPageSize(ps);
        return userService.queryFollowed(uid, pageBean);
    }


}
